﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace DreamBox.Net.Core
{
    public static class Text
    {
        public static string ReplaceHtml(string html)
        {
            Regex regex1 = new Regex(@"<script[\s\S]+</script *>", RegexOptions.IgnoreCase);
            Regex regex2 = new Regex(@" href *= *[\s\S]*script *:", RegexOptions.IgnoreCase);
            Regex regex3 = new Regex(@" on[\s\S]*=", RegexOptions.IgnoreCase);
            Regex regex4 = new Regex(@"<iframe[\s\S]+</iframe *>", RegexOptions.IgnoreCase);
            Regex regex5 = new Regex(@"<frameset[\s\S]+</frameset *>", RegexOptions.IgnoreCase);
            ////Regex regex6 = new Regex(@"\<img[^\>]+\>", RegexOptions.IgnoreCase);
            //Regex regex7 = new Regex(@"</p>", RegexOptions.IgnoreCase);
            //Regex regex8 = new Regex(@"<p>", RegexOptions.IgnoreCase);

            html = regex1.Replace(html, ""); //过滤<script></script>标记
            html = regex2.Replace(html, ""); //过滤href=javascript: (<A>) 属性
            html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on事件
            html = regex4.Replace(html, ""); //过滤iframe
            html = regex5.Replace(html, ""); //过滤frameset
            //html = regex6.Replace(html, ""); //过滤frameset
            //html = regex7.Replace(html, ""); //过滤frameset
            //html = regex8.Replace(html, ""); //过滤frameset
            return html;
        }
        public static string Replace(string text)
        {
            text = text.Replace(">", "&gt;");
            text = text.Replace("<", "&lt;");
            text = text.Replace(" ", "&nbsp;");
            text = text.Replace(" ", "&nbsp;");
            text = text.Replace("\"", "&quot;");
            text = text.Replace("\'", "'");
            return text;
        }
    }
}
